<template>
  <HomePanel title="热门品牌" sub-title="国际经典 品质保证" ref="target">
    <template v-slot:right>
      <a href="javascript:;" class="iconfont icon-angle-left prev" @click="activeIndex = 0" :class="{disabled: activeIndex === 0}"></a>
      <a href="javascript:;" class="iconfont icon-angle-right next" @click="activeIndex = 1" :class="{disabled: activeIndex === 1}"></a>
    </template>
    <div class="box" ref="box">
      <transition name='fade'>
      <ul class="list" :style="`transform: translateX(${ activeIndex ? '-50%' : 0 });`" v-if="list.length">
        <li v-for="i in list" :key="i.id">
          <RouterLink to="/">
            <img :src='i.picture' alt="">
          </RouterLink>
        </li>
      </ul>
      <!-- 🔔开发的时候可以先把所需的骨架屏写完，后面再添加 v-if 和 v-else -->
        <div v-else class="skeleton">
          <XtxSkeleton class="item" v-for="i in 5" :key="i" width="240px" height="305px"  bg="#e4e4e4" animated></XtxSkeleton>
        </div>
      </transition>
    </div>
  </HomePanel>
</template>

<script>
import { ref } from 'vue'
import { useLazyData } from '@/hooks/index'
import { findBrand } from '@/api/home'
import HomePanel from './home-panel.vue'
export default {
  name: 'HomeBrand',
  components: { HomePanel },
  setup () {
    const activeIndex = ref(0)
    const { target, list } = useLazyData(() => findBrand(10))
    // console.log(list)
    return {
      activeIndex, target, list
    }
  }
}
</script>

<style scoped lang='less'>
// .fade{
//   &-leave {
//     &-active {
//       position: absolute;
//       width: 100%;
//       transition: opacity .5s .2s;
//       z-index: 1;
//     }
//     &-to {
//       opacity: 0;
//     }
//   }
// }
.home-panel {
  background:#f5f5f5
}
.iconfont {
  width: 20px;
  height: 20px;
  background: #ccc;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: @xtxColor;
  &::before {
    font-size: 12px;
    position: relative;
    top: -2px
  }
  &.disabled {
    background: #ccc;
    cursor: not-allowed;
  }
}
.box {
  display: flex;
  width: 100%;
  height: 345px;
  overflow: hidden;
  padding-bottom: 40px;
  .list {
    width: 200%;
    display: flex;
    transition: all 1s;
    li {
      margin-right: 10px;
      width: 240px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      img {
        width: 240px;
        height: 305px;
      }
    }
  }
  .skeleton {
    width: 100%;
    display: flex;
    .item {
      margin-right: 10px;
      &:nth-child(5n) {
        margin-right: 0;
      }
    }
  }
}
</style>
